package com.rui.cn.provider.service.system.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.rui.cn.entity.system.SysPermission;
import com.rui.cn.provider.repository.system.SysPermissionDao;
import com.rui.cn.provider.service.system.SysPermissionService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhang123
 * @since 2018-01-15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SysPermissionServiceImpl extends ServiceImpl<SysPermissionDao,SysPermission> implements SysPermissionService {
    @Autowired
    private SysPermissionDao sysPermissionDao;
    @Override
    public List<SysPermission> loadUserPermission(Integer id){
        return  sysPermissionDao.loadUserPermission(id);
    }
    /**
     *@ 描述：列表页查询
     *@ 方法名：permissionList
     *@ 参数：[pagination, search, sortBy, order]
     *@ 返回值类型：java.util.List<com.rui.cn.entity.system.SysPermission>
     *@ 创建人：[zhang]
     *@ 创建时间：2018/4/29 0029-下午 23:50
     **/
    @Override
    public List<SysPermission> permissionList(Pagination pagination, String search, String sortBy, String order) {
        EntityWrapper<SysPermission> ew = new EntityWrapper<SysPermission>();
        ew.setEntity(new SysPermission());
        ew.like("permission",search).or().like("remark",search);
        if(StringUtils.isNotBlank(sortBy)){
            ew.and().orderBy(sortBy,order.equals("desc")?false:true);
        }
        return sysPermissionDao.selectPage(pagination,ew);
    }
    /**
     *@ 描述：角色的所有权限
     *@ 方法名：getRolePermiss
     *@ 参数：[roleid]
     *@ 返回值类型：java.util.List<com.rui.cn.entity.system.SysPermission>
     *@ 创建人：[zhang]
     *@ 创建时间：2018/4/29 0029-下午 23:50
     **/
    @Override
    public List<SysPermission> getRolePermiss(Integer roleid) {
        return sysPermissionDao.getRolePermiss(roleid);
    }

    @Override
    public SysPermission getPermissionInfo(Integer id) {
        return sysPermissionDao.getPermissionInfo(id);
    }

    @Override
    public boolean MyinsertOrUpdate(SysPermission permission) {
        return this.insertOrUpdate(permission);
    }
}
